package com.zprmb.udzt.activity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.JavascriptInterface;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.tencent.smtt.export.external.interfaces.ConsoleMessage;
import com.tencent.smtt.export.external.interfaces.SslErrorHandler;
import com.tencent.smtt.export.external.interfaces.WebResourceResponse;
import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
import com.zprmb.udzt.BaseActivity;
import com.zprmb.udzt.BbtApplication;
import com.zprmb.udzt.CustomDialog_view2;
import com.zprmb.udzt.CustomDialog_view3;
import com.zprmb.udzt.LoginActivity;
import com.zprmb.udzt.MainActivity;

import com.zprmb.udzt.R;
import com.zprmb.udzt.Set_tr_pw;

import com.zprmb.udzt.V6CheckPassWord;
import com.zprmb.udzt.V6DetailsActivity;
import com.zprmb.udzt.V6FingerPayPwdConfirmActivity;
import com.zprmb.udzt.V6LoginActivity;
import com.zprmb.udzt.V6ResultFinsh;
import com.zprmb.udzt.bean.FailBean;
import com.zprmb.udzt.bean.InBean;
import com.zprmb.udzt.bean.OutBean;
import com.zprmb.udzt.http.AjaxParams;
import com.zprmb.udzt.ll.BaseHelper;
import com.zprmb.udzt.util.Constant;
import com.zprmb.udzt.util.CustomDialog;
import com.zprmb.udzt.util.CustomDialog_view;
import com.zprmb.udzt.util.FingerSetting;
import com.zprmb.udzt.util.FingerprintUtil;
import com.zprmb.udzt.util.ToastUtil;
import com.zprmb.udzt.util.VolleryUtil;
import com.zprmb.udzt.view.WebViewDialog;

import org.json.JSONObject;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import de.greenrobot.event.EventBus;


@SuppressLint("SetJavaScriptEnabled")
public class NewV6WebviewChild2 extends BaseActivity implements PullToRefreshBase.OnRefreshListener<ScrollView> {
    String myphone;
    private ImageView iv_v4_web_back;
    private TextView tv_v4_web_title;
    private String title;
    private String ref = "";
    private String url;
    private CustomDialog_view.Builder builder;
    String version = "";
    private WebViewDialog dialog;
    private WebView v4_webview;
    private RelativeLayout rl_back;
    //	private ProgressBar bar;
    private boolean back = false;
    private SharedPreferences sha;
    int flag;
    Map<String, String> extraHeaders;
    private int reload = 0;
    private String active_url;
    CustomDialog.Builder customDialog;
    private int active;
    private ImageView iv_v4_nonetwork;
    String my_flagephone = "0";

    KeyguardManager keyguardManager = (KeyguardManager) BbtApplication.getContext().getSystemService(BbtApplication.getContext().KEYGUARD_SERVICE);
    private CustomDialog_view2.Builder builder2;
    private CustomDialog_view3.Builder builder3;
    private Handler handler2 = null;

    View web_head_view;

    View title_view;
//下拉刷新
//    private   PullToRefreshScrollView sv;

    public void checkUpdatePermission() {
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED
                ) {
//成功
            requestUpdatePermission();
        } else {
//失败

        }
    }

    private static final int REQUEST_UPDATE = 5;

    public void requestUpdatePermission() {
        String[] permissions = new String[]{Manifest.permission.CALL_PHONE};

        ActivityCompat.requestPermissions(this, permissions, 1);

    }

    View title_view_new;
    View view_titlebar;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.v6_webviewchild_activity);
        BbtApplication.getInstance().addActvity(this);
        EventBus.getDefault().register(this);
        Intent intent = getIntent();
//        checkPermission();
        view_titlebar=findViewById(R.id.view_titlebar);
        view_titlebar.setVisibility(View.GONE);

        title = intent.getStringExtra("title");
        url = intent.getStringExtra("url");
//        url = intent.getStringExtra("url");
        ref = getShare().getString("usercode", "");
        active = intent.getIntExtra("active", 0);
        active_url = intent.getStringExtra("active_url");
        dialog = new WebViewDialog(this);
//		IntentFilter mFilter = new IntentFilter();
//        mFilter.addAction("exit");
//        this.registerReceiver(myReceiver,mFilter);
//		Log.e("webview", url);
        // url = "account/invest/8F759CC2-65DB-11E5-AE96-5254002EAABD/contract";
        sha = getSharedPreferences("config", MODE_PRIVATE);
        version = getAppVersion();

        initView();
        initData();

        title_view_new = findViewById(R.id.title_view_new);
        title_view_new.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                NewV6WebviewChild2.this.finish();
            }
        });
        handler2 = new Handler();
        flag = getIntent().getIntExtra("flag", 0);
//		 v4_webview.loadUrl(url+getURLToken());
        v4_webview.loadDataWithBaseURL(null, url, "text/html", "utf-8", null);

        if (active == 1) {
//            v4_webview.loadUrl(active_url + getURLToken(), extraHeaders);

        } else {
//            v4_webview.loadUrl(url + getURLToken(), extraHeaders);
//				v4_webview.loadUrl("file:///android_asset/Untitled1.html");
//				Log.e("链接", url+getURLToken());
        }

    }


    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        if (active == 1) {
            active = 0;
        }
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        BbtApplication.getInstance().removeActvity(this);
        dialog.dismiss();
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode == KeyEvent.KEYCODE_BACK) {
          /*  LogUtils.e(NewV6WebviewChild2.this, v4_webview.canGoBack() + "");
            if (v4_webview.canGoBack()) {
                v4_webview.goBack();
            } else {
                Intent intent = new Intent();
                setResult(1, intent);
                finish();
            }*/
            NewV6WebviewChild2.this.finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    private void webViewPostUrl(String url) {
        v4_webview.postUrl(url, null);
    }

    private void initData() {
        extraHeaders = new HashMap<String, String>();
        extraHeaders.put("token", getToken());
        v4_webview.setWebViewClient(new WebViewClient() {

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Log.e("banner_url", url);
                if (url.indexOf("http://") == 0 || url.indexOf("https://") == 0) {

//						V6WebviewChild.this.url=url;

                    if (url.contains("redirect")) {
                        mpleaseLogin(NewV6WebviewChild2.this, 1, 0, 0);
                        /*      Intent intent = new Intent(NewV6WebviewChild2.this,
                                V6LoginActivity.class);
                        intent.putExtra("close", 1);
//							intent.putExtra("assets", 1);
                        intent.putExtra("web", 1);
                        startActivityForResult(intent, 1);*/
                    } else {
                        if (url.contains("?")) {
                            url = url + "&app=true&appversion=true&token=" + getURLToken();

                        } else {
                            url = url + "?app=true&appversion=true&token=" + getURLToken();

                        }

                        if (url.contains("intelliInto")) {
                            NewV6WebviewChild2.this.finish();
                        }


                        if (active == 1) {
                            active = 0;
                            v4_webview.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    v4_webview.clearHistory();
                                }
                            }, 1000);
                        }
                        Log.e("链接", url);
//						Log.e("ua", v4_webview.getSettings().getUserAgentString());
                        view.loadUrl(url, extraHeaders);


                    }


                    return true;
                }

                return true;
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub

                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub

                super.onPageFinished(view, url);
            }

            @Override
            public void onReceivedSslError(WebView arg0, SslErrorHandler arg1,
                                           com.tencent.smtt.export.external.interfaces.SslError arg2) {
                // TODO Auto-generated method stub
//				super.onReceivedSslError(arg0, arg1, arg2);
                arg1.proceed();

            }

            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view,
                                                              String url) {
                // TODO Auto-generated method stub
//		Log.e("header_ss", request.getRequestHeaders().toString());
                WebResourceResponse response = null;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                    response = super.shouldInterceptRequest(view, url);

                    if (url.contains("forapp=1")) {


                        if (url.contains(".css")) {
                            try {
                                String murl = url.substring(url.lastIndexOf("/") + 1, url.length());
//       			Log.e("css", murl);
                                response = new WebResourceResponse("text/css", "UTF-8", getAssets().open("css" + murl));
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                        if (url.contains(".png")) {
                            try {
                                String murl = url.substring(url.lastIndexOf("/") + 1, url.length());
//          	Log.e("png", murl);
                                response = new WebResourceResponse("image/png", "UTF-8", getAssets().open("image/" + murl));
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                        if (url.contains(".js")) {
                            try {
                                String murl = url.substring(url.lastIndexOf("/") + 1, url.length());
//             	  Log.e("css", "有");
                                response = new WebResourceResponse("application/x-javascript", "UTF-8", getAssets().open("public_js/" + murl));
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
                return response;
//	return super.shouldInterceptRequest(view, url);
            }

        });
        v4_webview.clearCache(true);

        v4_webview.setWebChromeClient(chromeClient);


        // 重新设置websettings WebSettings s = wb.getSettings();
        // s.setBuiltInZoomControls(true);
        // s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        v4_webview.getSettings().setUseWideViewPort(true);

        v4_webview.getSettings().setLoadWithOverviewMode(true);
        v4_webview.getSettings().setSavePassword(true);
        v4_webview.getSettings().setSaveFormData(true);
        v4_webview.getSettings().setJavaScriptEnabled(true);

        // enable navigator.geolocation
        v4_webview.getSettings().setGeolocationEnabled(true);
        v4_webview.getSettings().setGeolocationDatabasePath(
                "/data/data/org.itri.html5webview/databases/");
        // enable Web Storage: localStorage, sessionStorage
//		v4_webview.getSettings().setDomStorageEnabled(true);
        v4_webview.requestFocus();
        v4_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        // v4_webview.setScrollBarStyle(0);
        String ua = v4_webview.getSettings().getUserAgentString();
        v4_webview.getSettings().setUserAgentString(
                ua + "; " + "rmbbox_android");
        v4_webview.addJavascriptInterface(new JsInterfaces(NewV6WebviewChild2.this),
                "AndroidWebView");
        v4_webview.getSettings().setBuiltInZoomControls(true);
        v4_webview.getSettings().setLayoutAlgorithm(
                WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        v4_webview.getSettings().setDomStorageEnabled(true);
        // Set cache size to 8 mb by default. should be more than enough
        v4_webview.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
        // This next one is crazy. It's the DEFAULT location for your app's
        // cache
        // But it didn't work for me without this line.
        // UPDATE: no hardcoded path. Thanks to Kevin Hawkins
        String appCachePath = getApplicationContext().getCacheDir()
                .getAbsolutePath();
        v4_webview.getSettings().setAllowFileAccess(true);
        v4_webview.getSettings().setAppCacheEnabled(true);
        v4_webview.getSettings().setJavaScriptEnabled(true);
        v4_webview.getSettings().setAppCachePath(appCachePath);
        v4_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        v4_webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
//		v4_webview.getSettings().setSupportZoom(true);
        v4_webview.getSettings().setDefaultTextEncodingName("utf-8");
        if (v4_webview.getX5WebViewExtension() != null) {
            v4_webview.getX5WebViewExtension().setVerticalTrackDrawable(null);
        }
    }

    private void initData2() {
        extraHeaders = new HashMap<String, String>();
        extraHeaders.put("token", getToken());
        v4_webview.setWebViewClient(new WebViewClient() {

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Log.e("banner_url", url);
                if (url.indexOf("http://") == 0 || url.indexOf("https://") == 0) {

//						V6WebviewChild.this.url=url;

                    if (url.contains("redirect")) {
                        Intent intent = new Intent(NewV6WebviewChild2.this,
                                V6LoginActivity.class);
                        intent.putExtra("close", 1);
//							intent.putExtra("assets", 1);
                        intent.putExtra("web", 1);
                        startActivityForResult(intent, 1);
                    } else {
                        if (url.contains("?")) {
                            url = url + "&app=true&appversion=true&token=" + getURLToken();

                        } else {
                            url = url + "?app=true&appversion=true&token=" + getURLToken();
                        }
                        if (active == 1) {
                            active = 0;
                            v4_webview.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    v4_webview.clearHistory();
                                }
                            }, 1000);
                        }
                        Log.e("链接", url);
//						Log.e("ua", v4_webview.getSettings().getUserAgentString());
                        view.loadUrl(url, extraHeaders);
                    }
                    return true;
                }

                return true;
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub

                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub

                super.onPageFinished(view, url);
            }

            @Override
            public void onReceivedSslError(WebView arg0, SslErrorHandler arg1,
                                           com.tencent.smtt.export.external.interfaces.SslError arg2) {
                // TODO Auto-generated method stub
//				super.onReceivedSslError(arg0, arg1, arg2);
                arg1.proceed();

            }

            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view,
                                                              String url) {
                // TODO Auto-generated method stub
//		Log.e("header_ss", request.getRequestHeaders().toString());
                WebResourceResponse response = null;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                    response = super.shouldInterceptRequest(view, url);

                    if (url.contains("forapp=1")) {


                        if (url.contains(".css")) {
                            try {
                                String murl = url.substring(url.lastIndexOf("/") + 1, url.length());
//       			Log.e("css", murl);
                                response = new WebResourceResponse("text/css", "UTF-8", getAssets().open("css" + murl));
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                        if (url.contains(".png")) {
                            try {
                                String murl = url.substring(url.lastIndexOf("/") + 1, url.length());
//          	Log.e("png", murl);
                                response = new WebResourceResponse("image/png", "UTF-8", getAssets().open("image/" + murl));
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                        if (url.contains(".js")) {
                            try {
                                String murl = url.substring(url.lastIndexOf("/") + 1, url.length());
//             	  Log.e("css", "有");
                                response = new WebResourceResponse("application/x-javascript", "UTF-8", getAssets().open("public_js/" + murl));
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
                return response;
//	return super.shouldInterceptRequest(view, url);
            }

        });
        v4_webview.clearCache(true);

        v4_webview.setWebChromeClient(chromeClient2);


        // 重新设置websettings WebSettings s = wb.getSettings();
        // s.setBuiltInZoomControls(true);
        // s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        v4_webview.getSettings().setUseWideViewPort(true);

        v4_webview.getSettings().setLoadWithOverviewMode(true);
        v4_webview.getSettings().setSavePassword(true);
        v4_webview.getSettings().setSaveFormData(true);
        v4_webview.getSettings().setJavaScriptEnabled(true);

        // enable navigator.geolocation
        v4_webview.getSettings().setGeolocationEnabled(true);
        v4_webview.getSettings().setGeolocationDatabasePath(
                "/data/data/org.itri.html5webview/databases/");
        // enable Web Storage: localStorage, sessionStorage
//		v4_webview.getSettings().setDomStorageEnabled(true);
        v4_webview.requestFocus();
        v4_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        // v4_webview.setScrollBarStyle(0);
        String ua = v4_webview.getSettings().getUserAgentString();
        v4_webview.getSettings().setUserAgentString(
                ua + "; " + "rmbbox_android");
        v4_webview.addJavascriptInterface(new JsInterfaces(NewV6WebviewChild2.this),
                "AndroidWebView");
        v4_webview.getSettings().setBuiltInZoomControls(true);
        v4_webview.getSettings().setLayoutAlgorithm(
                WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        v4_webview.getSettings().setDomStorageEnabled(true);
        // Set cache size to 8 mb by default. should be more than enough
        v4_webview.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
        // This next one is crazy. It's the DEFAULT location for your app's
        // cache
        // But it didn't work for me without this line.
        // UPDATE: no hardcoded path. Thanks to Kevin Hawkins
        String appCachePath = getApplicationContext().getCacheDir()
                .getAbsolutePath();
        v4_webview.getSettings().setAllowFileAccess(true);
        v4_webview.getSettings().setAppCacheEnabled(true);
        v4_webview.getSettings().setJavaScriptEnabled(true);
        v4_webview.getSettings().setAppCachePath(appCachePath);
        v4_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        v4_webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
//		v4_webview.getSettings().setSupportZoom(true);
        v4_webview.getSettings().setDefaultTextEncodingName("utf-8");
        if (v4_webview.getX5WebViewExtension() != null) {
            v4_webview.getX5WebViewExtension().setVerticalTrackDrawable(null);
        }
    }

    String zhuanchustr;
    String zhuanchumoney;
    private String amountStr1;

    String amount = "";
    String amount1 = "";
    String time1 = "";
    String time2 = "";
    String time3 = "";
    String jsonObject = "";
    String url2;

    @Override
    protected void onActivityResult(int arg0, int arg1, Intent arg2) {
        // TODO Auto-generated method stub
        super.onActivityResult(arg0, arg1, arg2);

        if (arg1 == 1000) {
//            myWebView.loadUrl("javascript:myFunction()");
//            v4_webview.loadUrl(url + getURLToken());
            try {
                amount = arg2.getStringExtra("amount");
                time1 = arg2.getStringExtra("time");
                time3 = arg2.getStringExtra("time3");
                int a = Integer.valueOf(amount);
//                v4_webview.loadUrl("javascript:goInSuccess('amount','time1','time3')");
//                webview.loadUrl("javascript:tok('" + sName + "','" + uName + "')");
                v4_webview.loadUrl("javascript:goInSuccess('" + amount + "','" + time1 + "','" + time3 + "')");
//                v4_webview.loadUrl(jsonObject);
                v4_webview.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        v4_webview.clearHistory();
                    }
                }, 1000);
            } catch (Exception e) {
            }
        } else if (arg1 == 2000) {
            amount1 = arg2.getStringExtra("amount");
//            Toast.makeText(this, amount1 + "", Toast.LENGTH_SHORT).show();
            time2 = arg2.getStringExtra("time");


            v4_webview.loadUrl("javascript:goOutSuccess('" + amount1 + "','" + time2 + "')");
            v4_webview.postDelayed(new Runnable() {
                @Override
                public void run() {
                    v4_webview.clearHistory();
                }
            }, 1000);
        }

        if (arg2 != null) {

            Log.e("arg1", arg1 + "");
            if (arg1 == 1) {
                v4_webview.loadUrl(url + getURLToken());
                v4_webview.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        v4_webview.clearHistory();
                    }
                }, 1000);

            } else if (arg1 == 2) {
//                http://192.168.0.118:8080/h5/currentDetail?app=true&token=e4EYaoNC4UbWSKnkQYvyfVJRdHaFLsutAO5%2FlGMI4xB70eSvqYdhhNSmtMdYCbZ0x5epfvCEwCE%3D
                url = Constant.URL + "h5/currentDetail?app=true&token";
                v4_webview.reload();
            }
        } else {
            reload = 0;
            Log.e("arg1", arg1 + "");
        }
    }

    @SuppressLint("HandlerLeak")
    Handler handler3 = new Handler() {
        public void handleMessage(Message msg) {

            initView();
            initData2();


            if (active == 1) {
                v4_webview.loadUrl(active_url + getURLToken(), extraHeaders);

            } else {
                v4_webview.loadUrl(url + getURLToken(), extraHeaders);
//				v4_webview.loadUrl("file:///android_asset/Untitled1.html");
//				Log.e("链接", url+getURLToken());
            }

//            sv.onRefreshComplete();

        }

    };

    @Override
    public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {
        // TODO Auto-generated method stub
        handler3.postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub

                handler3.sendEmptyMessage(1);
            }
        }, 2000);
    }

    private final String ACTION_NAME = "智投宝结束";

    public class JsInterfaces {
        private Context mContext;


        public JsInterfaces(Context mContext) {
            super();
            this.mContext = mContext;

        }
    /*    //转入 连连
        @JavascriptInterface
        public void jumpWeb(String couponId) {
//            NewV6WebviewChild.this.finish();
//            Toast.makeText(mContext, couponId, Toast.LENGTH_SHORT).show();
//            startActivity(new Intent(NewV6WebviewChild.this,LoginActivity.class));
            Intent intent = new Intent(NewV6WebviewChild2.this, LoadingActivity2.class);
            intent.putExtra("couponId", couponId);
            startActivity(intent);
            NewV6WebviewChild2.this.finish();



            Intent mIntent2 = new Intent(ACTION_NAME);
            mIntent2.putExtra("yaner", "发送广播，相当于在这里传送数据");
            //发送广播
            sendBroadcast(mIntent2);

            V6iNewInvestCoupActivity.instance.finish();
        }*/

        @JavascriptInterface
        public void jumpWeb(String couponId, String orderId, String comment) {
//            NewV6WebviewChild.this.finish();
//            Toast.makeText(mContext, couponId, Toast.LENGTH_SHORT).show();

//            orderId comment
//            startActivity(new Intent(NewV6WebviewChild.this,LoginActivity.class));

            Log.d("3333333333333", couponId);
            Log.d("3333333333333", orderId);
            Log.d("3333333333333", comment);
            if (orderId.contains("失败")) {
                Intent intent = new Intent(NewV6WebviewChild2.this, FailYueActivity2.class);
                intent.putExtra("comment", orderId);
                startActivity(intent);

                Intent mIntent = new Intent(ACTION_NAME);
                mIntent.putExtra("yaner", "发送广播，相当于在这里传送数据");
                //发送广播
                sendBroadcast(mIntent);

                NewV6WebviewChild2.this.finish();
            } else {


                Log.d("3333333333333", couponId);
                Log.d("3333333333333", orderId);
                Log.d("3333333333333", comment);
                Intent intent = new Intent(NewV6WebviewChild2.this, LoadingActivity2.class);
                intent.putExtra("orderId", couponId);
                intent.putExtra("comment", orderId);
                intent.putExtra("productType", comment);
                startActivity(intent);
                NewV6WebviewChild2.this.finish();
                Intent mIntent = new Intent(ACTION_NAME);
                mIntent.putExtra("yaner", "发送广播，相当于在这里传送数据");
                sendBroadcast(mIntent);
                V6iNewInvestCoupActivity.instance.finish();
                NewV6WebviewChild2.this.finish();
            }
//            finish();
        }


        //转入
        @JavascriptInterface
        public void appZTBIn(String amount) {
            amountStr1 = amount;

            if (getisFingerPay() == 0) {
                Intent intent = new Intent(NewV6WebviewChild2.this, PayDexterityActivity2.class);
//
                intent.putExtra("amount", amount);
                startActivityForResult(intent, 1000);

            } else {

                onFingerprintClick2(1);

            }


        }

        //充值返回
      /*  @JavascriptInterface
        public void openExit() {
            V6WebviewChild.this.finish();
        }
*/
        //转出
        @JavascriptInterface
        public void appZTBOut(String amount, String type) {
            Log.d("-----------------", "33333333333333333");
            Log.d("-----------------", "33333333333333333");
            zhuanchustr = type;
            zhuanchumoney = amount;
            if (getisFingerPay() == 0) {
                Intent intent = new Intent(NewV6WebviewChild2.this, PayDexterityActivity3.class);

                intent.putExtra("amount", amount);
                intent.putExtra("type", type);
//                Toast.makeText(mContext, type + "", Toast.LENGTH_SHORT).show();
                startActivityForResult(intent, 2000);

            } else {
                onFingerprintClick3(1);

            }

        }

        //投资成功之后
        @JavascriptInterface
        public void goMyZTB() {
//            Toast.makeText(mContext, "完成", Toast.LENGTH_SHORT).show();
//            V6WebviewChild.this.finish();

            Intent intent2 = new Intent(NewV6WebviewChild2.this, V6WebviewChild3.class);
            intent2.putExtra("url", Constant.URL + "h5/currentDetail?app=true&token=");
            startActivity(intent2);
            NewV6WebviewChild2.this.finish();


        }

        // 在js中调用window.AndroidWebView.showInfoFromJs(name)，便会触发此方法。
        @JavascriptInterface
        public void pleaseLogin(String url) {
            Intent intent = new Intent(NewV6WebviewChild2.this,
                    V6LoginActivity.class);
            intent.putExtra("close", 1);
            intent.putExtra("web", 1);
            startActivityForResult(intent, 1);

        }

        @JavascriptInterface
        public void showInfoFromJs(String name) {

            initshare();
        }

        @JavascriptInterface
        public void finishActivity() {

            NewV6WebviewChild2.this.finish();
        }

        @JavascriptInterface
        public void toproduct(String[] list) {

            // Toast.makeText(Active_Webview.this, list.toString(),
            // 2000).show();

            Intent intent = new Intent(NewV6WebviewChild2.this,
                    V6DetailsActivity.class);
            intent.putExtra("flag", Boolean.parseBoolean(list[0]));
            intent.putExtra("name", list[1]);
            intent.putExtra("type", list[2]);
            intent.putExtra("id", list[3]);
            intent.putExtra("isred", list[4]);
            intent.putExtra("investId", list[5]);
            startActivity(intent);
        }

        @JavascriptInterface
        public void switchpage(String name) {


        }

        @JavascriptInterface
        public void finish(int type) {

            Log.e("type", "type=" + type);

            if (type == 0) {
                Log.e("type2", "type=" + type);
                NewV6WebviewChild2.this.finish();
                return;

            }
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub

                    if (v4_webview.canGoBack()) {
                        v4_webview.goBack();
                    } else {
                        if (dialog != null) {


                        }
                        Intent intent = new Intent();
                        setResult(1, intent);
                        NewV6WebviewChild2.this.finish();
                    }
                }
            });


        }

        @JavascriptInterface
        public void jsshare(String sharelink, final String description, final String title) {
//			Toast.makeText(V6WebviewChild.this, sharelink+sharelink+title, 2000).show();
            if (sharelink.length() > 1) {
                if (ref.equals("")) {


                } else {
                    sharelink = sharelink + "?ref=" + ref;

                }
                Message message = new Message();
                Bundle bundle = new Bundle();
                bundle.putString("title", title);
                bundle.putString("sharelink", sharelink);
                bundle.putString("description", description);
                message.setData(bundle);//bundle传值，耗时，效率低
                handler.sendMessage(message);//发送message信息
                message.what = 1;//标志是哪个线程传数据
            }
        }

        @JavascriptInterface
        public void jsshare2(String sharelink, String description, String title, String imageurl) {
//			Toast.makeText(V4WebViewActivity.this, sharelink+sharelink+title, 2000).show();
            if (sharelink.length() > 1) {
                if (ref.equals("")) {


                } else {
                    sharelink = sharelink + "?ref=" + ref;

                }

                Message message = new Message();
                Bundle bundle = new Bundle();
                bundle.putString("title", title);
                bundle.putString("sharelink", sharelink);
                bundle.putString("description", description);
                bundle.putString("imageurl", imageurl);
                message.setData(bundle);//bundle传值，耗时，效率低
                handler.sendMessage(message);//发送message信息
                message.what = 1;//标志是哪个线程传数据


            }
        }

        @JavascriptInterface
        public void Tel_phone(String phone) {
            myPhone = phone;
            if (sum == 0) {
                BaseHelper.showDialog2(NewV6WebviewChild2.this, "拨号", myPhone, 1);
            } else {
                checkUpdatePermission();
            }


        }

        @JavascriptInterface
        public int getstatus() {
            if (getShare().getString(getMobile(), "").equals("")) {
                return 0;
            } else {

                return 1;
            }
        }

        @JavascriptInterface
        public void gesture(int updata) {
//			Toast.makeText(V6WebviewChild.this, sharelink+sharelink+title, 2000).show();
            Log.e("gesture", updata + "");
            Intent intent = null;
            if (updata == 1) {
                intent = new Intent(NewV6WebviewChild2.this, V6CheckPassWord.class);
                intent.putExtra("open", updata);
                startActivityForResult(intent, 1);
            } else {
                intent = new Intent(NewV6WebviewChild2.this, V6CheckPassWord.class);
                intent.putExtra("open", updata);
                startActivityForResult(intent, 1);
            }

        }

        @JavascriptInterface
        public void settab(int i) {
            if (MainActivity.instance != null) {
                MainActivity.instance.finish();
            }
            Editor ed = sha.edit();
            ed.putInt("tab", i);
            ed.commit();
            Intent intent = new Intent(NewV6WebviewChild2.this,
                    MainActivity.class);
            intent.putExtra("licai", 1);
            startActivity(intent);
        }

        @JavascriptInterface
        public void signout() {
//			runOnUiThread(new Runnable() {
//
//				@Override
//				public void run() {
//					// TODO Auto-generated method stub
            sign_out();
//				}
//			});

//			MainActivity.newInstance().setCurrentTabByTag("tab_tag_shouye");

        }

        @JavascriptInterface
        public void setTitle(String title) {
            tv_v4_web_title.setText(title);

        }

        @JavascriptInterface
        public void setactivity(String activity) {

            Log.e("activity", activity);
            if (active == 1) {
                NewV6WebviewChild2.this.finish();
//				Intent mIntent = new Intent();
//                mIntent.setAction("exit");
//                sendBroadcast(mIntent);
            }
            Intent intent;
            try {
                intent = new Intent(NewV6WebviewChild2.this,
                        Class.forName(activity));
                startActivity(intent);
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        @JavascriptInterface
        public void setactivityIntent(String activity, String key, String value) {


            Intent intent;
            try {

                intent = new Intent(NewV6WebviewChild2.this,
                        Class.forName(activity));
                intent.putExtra("webview", 1);
                intent.putExtra(key, value);
                startActivity(intent);
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        @JavascriptInterface
        public String getAppVersionforM() {

            return version;

        }

        @JavascriptInterface
        public void addmoney() {
            verifuser("1");
        }

        @JavascriptInterface
        public void setFingerstatus(final int status) {
            // 设置指纹
            runOnUiThread(new Runnable() {
                public void run() {
                    onFingerprintClick(status, 1);
                }
            });

        }

        @JavascriptInterface
        public void setFingerPaystatus(final int status) {
            // 设置指纹支付
            runOnUiThread(new Runnable() {
                public void run() {
                    onFingerprintClick(status, 2);
                }
            });
        }

        @JavascriptInterface
        public void openFingerPayDialog() {
            if (getisFinger() == 1 & getisFingerPay() == 0) {
                showDialog();

                return;
            }
        }

        @JavascriptInterface
        public int getFingerSupport() {
            Log.e("support", getisFinger() + "");
            return getisFinger();


        }

        @JavascriptInterface
        public int getFingerstatus() {


            return getopenfinger();


        }

        @JavascriptInterface
        public int getFingerPaystatus() {
            return getisFingerPay();

        }

        @JavascriptInterface
        public String getApptoken() {
            return getToken();
        }

        public void sendInfoToJs(View view) {
            String msg = getToken();
            Log.e("web", "调用");
            // 调用js中的函数：showInfoFromJava(msg)

        }
    }

    Handler handler = new Handler() {
        public void handleMessage(Message msg) {

            if (msg.what == 1) {
                share(NewV6WebviewChild2.this, msg.getData().getString("description"), msg.getData().getString("title"), msg.getData().getString("sharelink"), msg.getData().getString("imageurl"));
            }


        }

        ;
    };


    private final int REQUEST_CODE_PERMISSIONS = 2;

    int sum = 1;
    String myPhone = "";

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
//        Log.d("onRequestPermissionsResult", "--> onRequestPermissionsResult:permissions = " + Arrays.toString(permissions));
        Log.d("SplashActivity", "--> onRequestPermissionsResult:grantResults = " + Arrays.toString(grantResults));
        Log.d("SplashActivity", "--> onRequestPermissionsResult:permissions = " + Arrays.toString(permissions));
        Log.d("SplashActivity", "--> onRequestPermissionsResult:grantResults = " + Arrays.toString(grantResults));
        sum = 0;
        for (int grant : grantResults) {
            sum += grant;
        }
        if (sum < 0) {

        } else {
//            BaseHelper.showDialog2(V6WebviewChild.this, "拨号", myPhone, 1);
        }


    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    public void sign_out() {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                Log.e("signout", jsonObject.toString());
                if (jsonObject.optInt("success") == 1) {
                    SharedPreferences sharedPreferences = getSharedPreferences("config", MODE_PRIVATE);
                    Editor ed = sharedPreferences.edit();
                    ed.putString("token", "");
                    ed.putString(getMobile(), "");
                    ed.putString("mobile", "");
                    ed.putString("usercode", "");
                    ed.commit();
                    Intent intent9 = new Intent(NewV6WebviewChild2.this, MainActivity.class);
//				intent9.putExtra("out", 1);
                    startActivity(intent9);
                }
            }


            @Override
            public void onError() {
                // TODO Auto-generated method stub

            }
        };
        volleryUtil.setHeaders("token", getToken());
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(true);
        volleryUtil.execute(NewV6WebviewChild2.this, Constant.URL + "/api/logout", "");
    }

    private void initshare() {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                Log.e("invate", jsonObject.toString());
                if (jsonObject.optInt("success") == 1) {
                    JSONObject json = jsonObject.optJSONObject("data");
                    String linkurl = "";
                    if (ref.equals("")) {
                        linkurl = json.optString("linkUrl");

                    } else {
                        linkurl = json.optString("linkUrl") + "?ref=" + ref;

                    }


                    share(NewV6WebviewChild2.this, json.optString("description"), json.optString("title"), linkurl, "");
                } else {

                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

            }
        };
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(true);
        volleryUtil.execute(NewV6WebviewChild2.this, Constant.URL + "/api/shareProductContent/inviteFriend/inviteFriend", "");
    }

    public void shareforjs(String sharelink, String description, String title) {
        if (ref.equals("")) {


        } else {
            sharelink = sharelink + "?ref=" + ref;

        }
        share(NewV6WebviewChild2.this, description, title, sharelink, "");
    }

    WebChromeClient chromeClient = new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            Log.e("进度", newProgress + "");
            if (newProgress == 100) {
                dialog.dismiss();
            } else {
                if (dialog.isShowing() == false & !NewV6WebviewChild2.this.isFinishing()) {
                    dialog.show();
                }

            }
            super.onProgressChanged(view, newProgress);

        }


        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            Log.e("console", "[" + consoleMessage.messageLevel() + "] " + consoleMessage.message() + "(" + consoleMessage.sourceId() + ":" + consoleMessage.lineNumber() + ")");
            return super.onConsoleMessage(consoleMessage);
        }
    };
    WebChromeClient chromeClient2 = new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            Log.e("进度", newProgress + "");
            if (newProgress == 100) {
                dialog.dismiss();
            } else {
                if (dialog.isShowing() == false & !NewV6WebviewChild2.this.isFinishing()) {
                    dialog.dismiss();
                }

            }
            super.onProgressChanged(view, newProgress);

        }


        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            Log.e("console", "[" + consoleMessage.messageLevel() + "] " + consoleMessage.message() + "(" + consoleMessage.sourceId() + ":" + consoleMessage.lineNumber() + ")");
            return super.onConsoleMessage(consoleMessage);
        }
    };

    private void verifuser(final String who) {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    JSONObject json = jsonObject.optJSONObject("data");

                    if (json.optBoolean("nameAuth") && json.optBoolean("isBindCard")) {
                        if (who.equals("1")) {
//
//                            Intent intent = new Intent(NewV6WebviewChild2.this, V4AddMoneySActiviy.class);
//                            startActivity(intent);
                        } else {

                        }
                    } else {

//							if (!json.optBoolean("nameAuth")) {
//								Intent intent = new Intent(AssetsActivity.this,Real_Name.class);
//								startActivity(intent);
//								return;
//							}
                        if (json.optString("bankMobileStatus") != null && !json.optString("bankMobileStatus").equals("") && json.optString("bankMobileStatus").equals("WAIT_CHECK")) {
                         /*   Intent intent = new Intent(NewV6WebviewChild2.this, BankCardActivity.class);
                            intent.putExtra("bankcard", json.optString("cardNo"));
                            intent.putExtra("isbank", 1);
                            intent.putExtra("logourl", json.optString("logoUrl"));
                            intent.putExtra("banknameEn", json.optString("bankNameEn"));
                            intent.putExtra("banknameCn", json.optString("bankNameCn"));
                            intent.putExtra("status", json.optString("bankMobileStatus"));
                            startActivity(intent);
                            return;*/
                        }
                        if (!json.optBoolean("isBindCard")) {
//								!json.optBoolean("isBindCard")

                        }

                    }
                } else {
                    if (jsonObject.optString("comment").equals("please login")) {
                        Intent intent = new Intent(NewV6WebviewChild2.this,
                                LoginActivity.class);
                        intent.putExtra("close", 1);
                        startActivity(intent);
                    }
                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

            }
        };
        volleryUtil.setRequestMethod(0);
        volleryUtil.setHeaders("token", getToken());
        volleryUtil.setShow(true);
        volleryUtil.execute(this, Constant.URL + "/api/v5/user/userInfo", "");
    }

    public void onFingerprintClick(final int status, final int type) {

        FingerprintUtil.callFingerPrint(new FingerprintUtil.OnCallBackListenr() {

            @Override
            public void onSupportFailed() {
                showToast("当前设备不支持指纹");
            }

            @Override
            public void onInsecurity() {
                customDialog = new CustomDialog.Builder(NewV6WebviewChild2.this);

                customDialog.setMessage("请在系统设置中开启指纹功能");
                customDialog.create().setCancelable(false);
                customDialog.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        FingerSetting.openFingerPrintSettingPage(NewV6WebviewChild2.this);
                        customDialog.create().dismiss();
                        customDialog = null;
                    }
                });
                customDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        customDialog.create().dismiss();
                        customDialog = null;

                    }
                });
                customDialog.create().show();
            }

            @Override
            public void onEnrollFailed() {
                showToast("请到设置中设置指纹");
            }

            @Override
            public void onAuthenticationStart() {
                builder = new CustomDialog_view.Builder(NewV6WebviewChild2.this);
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        FingerprintUtil.cancel();
                        builder.create().dismiss();
                    }
                });
                builder.setMessage("“优点智投”的 Touch ID");
                builder.setMessage2("请验证已有手机指纹");
                builder.create().setCancelable(false);
                builder.create().show();
                Log.e("dialog", builder.create() + "");
            }

            @Override
            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                showToast(errString.toString());
//                Log.e("dialog", builder.create()+"");
                if (builder.create() != null) {
                    builder.create().mdissmis();
                }
            }

            @Override
            public void onAuthenticationFailed() {
                showToast("认证失败");
            }

            @Override
            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                showToast(helpString.toString());
            }

            @Override
            public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
                showToast("认证成功");
                Log.e("dialog", builder.create() + "");
//                Log.e("object", builder.create()+""+builder.create().isShowing()+"");
                if (builder.create() != null) {
                    builder.create().mdissmis();
                    if (type == 1) {
                        Editor editor = sha.edit();
                        editor.putInt(getMobile() + "openfinger", status);
                        editor.commit();

                    } else {
                        if (status == 1) {
                            Intent intent = new Intent(NewV6WebviewChild2.this, V6FingerPayPwdConfirmActivity.class);
                            startActivityForResult(intent, 1);
                        } else {
                            Editor editor = sha.edit();
                            editor.putInt(getMobile() + "fingerPay", status);
                            editor.commit();
                        }

                    }
                    v4_webview.reload();
                }

            }
        });
    }

    private void showDialog() {
        customDialog = new CustomDialog.Builder(NewV6WebviewChild2.this);

        customDialog.setMessage("优点智投上线指纹支付功能，是否开启使用？");
        customDialog.create().setCancelable(false);
        customDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                customDialog.create().dismiss();
            }
        });
        customDialog.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                mStartActivity(NewV6WebviewChild2.this, V6FingerPayPwdConfirmActivity.class);
                customDialog.create().dismiss();
                finish();
            }
        });
        customDialog.create().show();
    }

    private ImageView img_share;

    private void initView() {
        iv_v4_web_back = (ImageView) findViewById(R.id.img_back);
        rl_back = (RelativeLayout) findViewById(R.id.rl_back);
        web_head_view = findViewById(R.id.web_head_view);
        img_share = (ImageView) findViewById(R.id.img_share);
        web_head_view.setVisibility(View.GONE);
        tv_v4_web_title = (TextView) findViewById(R.id.tv_title);
//		bar = (ProgressBar) findViewById(R.id.myProgressBar);

        try {

            if (url.contains("currentDetail")) {
                tv_v4_web_title.setText("智投宝");
            } else if (url.contains("myNewInvest")) {
                tv_v4_web_title.setText("优享计划");
            } else if (url.contains("fundRecord")) {
                tv_v4_web_title.setText("资金流水");
            } else if (url.contains("myVoucher")) {
                tv_v4_web_title.setText("我的抵扣券");
            } else if (url.contains("myCoupon")) {
                tv_v4_web_title.setText("我的加息券");
            } else if (url.contains("myExperience")) {
                tv_v4_web_title.setText("我的体验金");
            } else if (url.contains("giftcard")) {
                tv_v4_web_title.setText("我的红包");
            } else if (url.contains("inviteFriends")) {
                tv_v4_web_title.setText("我的邀请");
            } else if (url.contains("accountCenter")) {
                tv_v4_web_title.setText("个人中心");
            } else {
                tv_v4_web_title.setText("个人中心");

            }

        } catch (Exception e) {

        }


        iv_v4_nonetwork = (ImageView) findViewById(R.id.iv_v4_nonetwork);
        rl_back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (v4_webview.canGoBack()) {
                    v4_webview.goBack();
                } else {
                    finish();
                }
            }
        });
        iv_v4_web_back.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                if (v4_webview.canGoBack()) {
                    v4_webview.goBack();
                } else {
                    finish();
                }
            }
        });

        tv_v4_web_title.getPaint().setFakeBoldText(true);
//		if (title.indexOf("了解") == 0) {
////			tv_v4_web_title.setText("项目详情");
//		} else {
//
////			tv_v4_web_title.setText(title);
//		}
        v4_webview = (WebView) findViewById(R.id.v4_webview);
        title_view = findViewById(R.id.title_view);
        if (!network()) {
            v4_webview.setVisibility(View.GONE);
            web_head_view.setVisibility(View.GONE);
            iv_v4_nonetwork.setVisibility(View.VISIBLE);
            tv_v4_web_title.setVisibility(View.VISIBLE);
            title_view.setVisibility(View.VISIBLE);
            img_share.setVisibility(View.GONE);
        } else {
            v4_webview.setVisibility(View.VISIBLE);
            web_head_view.setVisibility(View.GONE);
            iv_v4_nonetwork.setVisibility(View.GONE);
            tv_v4_web_title.setVisibility(View.GONE);
            title_view.setVisibility(View.GONE);
        }
        iv_v4_nonetwork.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!network()) {
                    iv_v4_nonetwork.setVisibility(View.VISIBLE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView

                    v4_webview.setVisibility(View.GONE);
                    title_view.setVisibility(View.VISIBLE);

                    web_head_view.setVisibility(View.GONE);
                    Toast.makeText(NewV6WebviewChild2.this, "当前无网络", Toast.LENGTH_SHORT).show();
                } else {
                    iv_v4_nonetwork.setVisibility(View.GONE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView

                    v4_webview.setVisibility(View.VISIBLE);
                    title_view.setVisibility(View.GONE);
                    web_head_view.setVisibility(View.GONE);
//                    initData();
                    v4_webview.reload();
                    initData();
                }
            /*    initView();
//                v4_webview.loadUrl(active_url + getURLToken(), extraHeaders);
            v4_webview.reload();
                initData();*/
            }
        });

    }


    public void onFingerprintClick2(final int type) {

        FingerprintUtil.callFingerPrint(new FingerprintUtil.OnCallBackListenr() {

            @Override
            public void onSupportFailed() {
                showToast("当前设备不支持指纹");
            }

            @Override
            public void onInsecurity() {
                showToast("当前设备未处于安全保护中");
            }

            @Override
            public void onEnrollFailed() {
                showToast("请到设置中设置指纹");
            }

            @Override
            public void onAuthenticationStart() {
//                li_tishi.getVisibility()
                EventBus.getDefault().post(0);
//                builder2.create().show();

            }

            @Override
            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                if (errMsgId == 7) {
//                    verityUser();
                } else {

                    showToast(errString.toString());
                }
                if (builder2.create() != null) {
//                    builder2.create().dismiss();
                    EventBus.getDefault().post(2);
                }


            }

            @Override
            public void onAuthenticationFailed() {
                showToast("再试一次");
            }

            @Override
            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                showToast(helpString.toString());
            }

            @Override
            public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
//                showToast("解锁成功");

                /*        if (builder2.create() != null) {
                            builder2.create().dismiss();
                        }*/


                if (!network()) {
                    Toast.makeText(NewV6WebviewChild2.this, "当前无网络", Toast.LENGTH_SHORT).show();
                    EventBus.getDefault().post(2);

                } else {
                    EventBus.getDefault().post(1);
                    invest();
                }


//                builder2.create().dismiss();
//                invest();


            }


        });
    }

    public void onEventMainThread(Integer type) {
        Log.e("---", "EventBus收到int:" + type);
        if (type == 0) {

            builder2 = new CustomDialog_view2.Builder(NewV6WebviewChild2.this);
            builder2.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    FingerprintUtil.cancel();
                    EventBus.getDefault().post(2);
//                    builder2.create().dismiss();
                }
            });
            builder2.setMessage("“优点智投”的 Touch ID");
            builder2.setMessage2("请验证已有手机指纹");
            builder2.create().setCancelable(false);
            builder2.create().show();

        } else if (type == 1) {
            builder2.create().dismiss();

        } else if (type == 2) {
            builder2.create().dismiss();

        } else if (type == 3) {
            builder3 = new CustomDialog_view3.Builder(NewV6WebviewChild2.this);

            builder3.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    FingerprintUtil.cancel();
//                    builder3.create().dismiss();
                    EventBus.getDefault().post(4);
                }
            });
            builder3.setMessage("“优点智投”的 Touch ID");
            builder3.setMessage2("请验证已有手机指纹");
            builder3.create().setCancelable(false);
            builder3.create().show();
        } else if (type == 3) {
            builder3.create().dismiss();
        } else if (type == 4) {
            builder3.create().dismiss();
        }

    }

    /**
     * 转入
     */
    private void invest() {

        AjaxParams params = new AjaxParams();
        params.put("amount", amountStr1);
        params.put("payPass", "");
//        params.put("payPass", "");
        params.put("productType", "CURRENT_DEPOSIT");
        params.put("productId", "");
        params.put("payType", "FINGERPRINT");
//        params.put("useCurrentAmountToInvest", false + "");
        VolleryUtil vollery = new VolleryUtil() {
            InBean inBean;

            @Override
            public void onUpDate(final JSONObject jsonObject) {
                // TODO Auto-generated method stub
                Log.e("转如", jsonObject.toString());

                if (jsonObject.optInt("success") == 1) {

                    Gson gson = new Gson();
                    inBean = new InBean();
                    inBean = gson.fromJson(jsonObject.toString(), InBean.class);

                    ToastUtil.showCenterToast(
                            NewV6WebviewChild2.this,
                            inBean.getComment());

                    refresh(inBean.getData().getAmount(), inBean.getData().getDueDate(), inBean.getData().getCountRateDate());
//                    v4_webview.loadUrl("javascript:goInSuccess('" + amount + "','" + time1 + "','" + time3 + "')");

                } else if (jsonObject.optInt("success") == 0) {

                    Gson gson = new Gson();
                    FailBean failBean = new FailBean();
                    failBean = gson.fromJson(jsonObject.toString(), FailBean.class);
                    ToastUtil.showCenterToast(
                            NewV6WebviewChild2.this,
                            failBean.getComment());

                } else {

                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

                Intent intent = new Intent(NewV6WebviewChild2.this, V6ResultFinsh.class);
                intent.putExtra("title", "转出结果");
                intent.putExtra("description2", "确认转出结果！若转出失败请重新操作");
                intent.putExtra("description1", "您好，系统正在处理中，\n请3~5分钟之后前往 “我的账户-智投宝”");
                intent.putExtra("button", "我的智投宝");
                startActivity(intent);
                NewV6WebviewChild2.this.finish();
            }
        };


        vollery.setShow(true);
  /*      vollery.setHeaders("token", getToken());
        vollery.setHeaders("client", "android");*/
        vollery.setHeaders("token", getToken());
        vollery.setHeaders("client", "android");
        vollery.setHeaders("deviceId", getdeviceId());
        vollery.setHeaders("deviceToken", getdevice_token());
        vollery.setRequestMethod(1);
        vollery.execute(this, Constant.URL
                + "api/v2/claim/fund/invest?", params.toString());

    }

    public void refresh(String amount, String time1, String time3) {

//         url="javascript:goInSuccess('" + amount + "','" + time1 + "','" + time3 + "')";

        v4_webview.loadUrl("javascript:goInSuccess('" + amount + "','" + time1 + "','" + time3 + "')");


//        ZHUJI3
//                v4_webview.loadUrl(jsonObject);
        v4_webview.postDelayed(new Runnable() {
            @Override
            public void run() {
                v4_webview.clearHistory();
            }
        }, 1000);
    }

    public void refresh2(String amount, String time1) {


        v4_webview.loadUrl("javascript:goOutSuccess('" + amount + "','" + time1 + "')");

        v4_webview.postDelayed(new Runnable() {
            @Override
            public void run() {
                v4_webview.clearHistory();
            }
        }, 1000);
    }

    public void onFingerprintClick3(final int type) {

        FingerprintUtil.callFingerPrint(new FingerprintUtil.OnCallBackListenr() {

            @Override
            public void onSupportFailed() {
                showToast("当前设备不支持指纹");
            }

            @Override
            public void onInsecurity() {
                showToast("当前设备未处于安全保护中");
            }

            @Override
            public void onEnrollFailed() {
                showToast("请到设置中设置指纹");
            }

            @Override
            public void onAuthenticationStart() {
//                li_tishi.getVisibility()
                EventBus.getDefault().post(3);

            }

            @Override
            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                if (errMsgId == 7) {
//                    verityUser();
                } else {

                    showToast(errString.toString());
                }
              /*  if (builder3.create() != null) {
                    builder3.create().dismiss();
                }*/
                EventBus.getDefault().post(4);


            }

            @Override
            public void onAuthenticationFailed() {
                showToast("再试一次");
            }

            @Override
            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                showToast(helpString.toString());
            }

            @Override
            public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
//                showToast("解锁成功");

                EventBus.getDefault().post(4);
                if (!network()) {
                    Toast.makeText(NewV6WebviewChild2.this, "当前无网络", Toast.LENGTH_SHORT).show();


                } else {
//                    EventBus.getDefault().post(4);
                    invest2();
                }

            }


        });
    }

    /**
     * 转出
     */
    private void invest2() {

        AjaxParams params = new AjaxParams();
        params.put("amount", zhuanchumoney);
//        params.put("payPass", "1213456");
//        params.put("productType", "CURRENT_DEPOSIT");
//                  [payDic setObject:pasword.length>0?@"PWD":@"FINGERPRINT" forKey:@"payType"];
        params.put("outStyle", zhuanchustr);
        params.put("productId", "");
        params.put("payType", "FINGERPRINT");
        VolleryUtil vollery = new VolleryUtil() {
            OutBean outBean;

            @Override
            public void onUpDate(final JSONObject jsonObject) {
                // TODO Auto-generated method stub
                Log.e("转如", jsonObject.toString());


                if (jsonObject.optInt("success") == 1) {

                    Gson gson = new Gson();
                    outBean = new OutBean();
                    outBean = gson.fromJson(jsonObject.toString(), OutBean.class);

                    ToastUtil.showCenterToast(
                            NewV6WebviewChild2.this,
                            outBean.getComment());

                    refresh2(outBean.getData().getAmount(), outBean.getData().getExpectedArriveTime());

                } else if (jsonObject.optInt("success") == 0) {

                    Gson gson = new Gson();
                    FailBean failBean = new FailBean();
                    failBean = gson.fromJson(jsonObject.toString(), FailBean.class);
                    ToastUtil.showCenterToast(
                            NewV6WebviewChild2.this,
                            failBean.getComment());

                } else {

                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

                Intent intent = new Intent(NewV6WebviewChild2.this, V6ResultFinsh.class);
                intent.putExtra("title", "转出结果");
                intent.putExtra("description2", "确认转出结果！若转出失败请重新操作");
                intent.putExtra("description1", "您好，系统正在处理中，\n请3~5分钟之后前往 “我的账户-智投宝”");
                intent.putExtra("button", "我的智投宝");
                startActivity(intent);
                NewV6WebviewChild2.this.finish();
            }
        };


        vollery.setShow(true);
//        vollery.setHeaders("token", getToken());
//        vollery.setHeaders("client", "android");
        vollery.setHeaders("token", getToken());
        vollery.setHeaders("client", "android");
        vollery.setHeaders("deviceId", getdeviceId());
        vollery.setHeaders("deviceToken", getdevice_token());
        vollery.setRequestMethod(1);
        vollery.execute(this, Constant.URL
                        + "api/v2/claim/fund/current/redemption?",
                params.toString());

    }
}
